package com.catchu.pattern.creational.观察者模式.subject;

import com.catchu.pattern.creational.观察者模式.observer.Observer;

import java.util.Vector;

/**
 * 被观察者基类
 */
public abstract class BaseSubject {

    private Vector<Observer> observers = new Vector<>(10);

    public void addObserver(Observer observer){
        observers.add(observer);
    }

    public void removeObserver(Observer observer){
        observers.remove(observer);
    }

    /**
     * 回调观察者
     */
    public void notifyObservers(){
        for(Observer observer : observers){
            observer.update();
        }
    }
}
